#!/bin/sh
cd "${0%/*}" || exit                                # Run from this directory
export WM_CONTINUE_ON_ERROR=true                    # Optional unit
. ${WM_PROJECT_DIR:?}/wmake/scripts/cmakeFunctions  # Cmake functions
. ${WM_PROJECT_DIR:?}/wmake/scripts/AllwmakeParseArguments
#------------------------------------------------------------------------------
# Copyright (C) 2020 OpenCFD Ltd.
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# Note
#     - '-prefix=..' to define installation prefix (default: FOAM_USER_LIBBIN)
#     - MPI detection may not work properly with later VTK/ParaView versions
#------------------------------------------------------------------------------

# Default to user location
: "${FOAM_MODULE_PREFIX:=${FOAM_USER_LIBBIN%/*}}"
: "${CMAKE_INSTALL_PREFIX:=$FOAM_MODULE_PREFIX}"

export CMAKE_INSTALL_PREFIX
cmakeOpts="-DCMAKE_INSTALL_PREFIX=$CMAKE_INSTALL_PREFIX"

#------------------------------------------------------------------------------

echo "======================================================================"
echo "${PWD##*/} : $PWD"
echo

unset depend catalystDebug


# If available, prefer use of ParaView MESA
if [ -d "$ParaView_MESA_DIR" ]
then
    export ParaView_DIR="$ParaView_MESA_DIR"
fi

if [ -d "$ParaView_DIR" ]
then
    depend="ParaView_DIR=$ParaView_DIR"
fi


if [ "$targetType" = objects ]
then
    depend=ignore
elif [ -n "$depend" ]
then
    if command -v cmake >/dev/null
    then
        echo "catalyst prefix : $CMAKE_INSTALL_PREFIX"
        cmakeVersionedInstall "$depend" "$PWD" $cmakeOpts || {
            echo
            echo "    WARNING: incomplete build of ParaView Catalyst"
            echo
        }
    else
        echo "==> skip catalyst (needs cmake)"
    fi
else
    echo "WARNING: skip ParaView Catalyst (missing or incorrrect ParaView)"
fi

echo "======================================================================"

#------------------------------------------------------------------------------
